/**************************************************************************************
*  Component of benchmarking program.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************************/
public class StringBenchmarkUnit extends BenchmarkUnit {

    public int wIterationCount;
    public String sPattern1;
    public String sPattern2;
    public String sPattern3;

    public StringBenchmarkUnit() {
        name = "String";
        wIterationCount = 10;
        sPattern1 = "one ";
        sPattern2 = "two ";
        sPattern3 = "three ";
    }

    public int execute() {

        StringBuffer stringBuffer = new StringBuffer("Test");
        for (int j = 0; j < wIterationCount; j++)
            stringBuffer.append(sPattern1).append(sPattern2).append(sPattern3);

        stringBuffer.append("four");
        int i=0;
        for (int k = 0; k < wIterationCount; k++)
            i += stringBuffer.toString().indexOf("four", k * 10);

        return i;
    }

}

